#include "fig_ui_popupcontroller.h"
#include "gen_game_state.h"
#include "fig_sounds.h"

#include "gameflow/ui_popup.h"

FIGUIPopupController::FIGUIPopupController()  : 
											FIGUIPopupAnimator("ui/popup_controller.ui","")
{
	
	
	if(m_pPopup)
	{
		this->SetCloseButton("controller_img");
		AddToNaviationUI(m_pPopup->GetWidget("controller_img"));
		m_pPopup->SetWidgetFunctor("controller_img", UI_DELEGATE(FIGUIPopupController, OnButtonClose));

		FIGUIPopupAnimatorMgr::Instance().AddPopupAnimator(FIGUIPopupAnimatorMgr::POPUP_NAMES_CONTROLLER,this);
		ui::UIWidget* pWidget = m_pPopup->GetWidget("controller_img");
		if(pWidget)
		{
			const float AspectRatioCreated = 640.0f / 960.0f;
			const float AsepctRatioCurrent = (float)GetGraphics()->GetScreenWidth() / (float)GetGraphics()->GetScreenHeight();
			const float NewHScale =  AsepctRatioCurrent / AspectRatioCreated;	

			math::Vec2 TempVec = pWidget->GetSize();
			pWidget->SetSize( math::Vec2(TempVec.x, TempVec.y * NewHScale ));
		}

	}
	m_Type = ANIMATION_SLIDEFROMTOP;

}

void		FIGUIPopupController::Hide()
{
	if(GENGameState::GetGame())
		GENGameState::GetGame()->UnPause();
	audio::BassAudio::Instance().RestartAll();

	FIGUIPopupAnimator::Hide();
}

void		FIGUIPopupController::Show()
{
	if(GENGameState::GetGame())
		GENGameState::GetGame()->Pause();

	audio::BassAudio::Instance().PauseAll();
	FIGUIPopupAnimator::Show();

}

void DELEGATE_CALL	FIGUIPopupController::OnButtonClose(ui::UIWidget::WIDGET_EVENT Event, ui::UIWidget* pWidget)
{
	this->Hide();
}
	